#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
namespace io{

template<typename T>
inline void gi(T &x)
{
	x=0;char ch=getchar();
	while(ch<'0'||'9'<ch) ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
}
template<typename T>
void print(T x)
{
	if(x<0) putchar('-'),print(-x);
	else if(x<=9) putchar(x+'0');
	else print(x/10),putchar(x%10+'0');
}

}using io::gi;using io::print;

set<ll> st;
ll sum=0;
int Q;
signed main()
{
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	gi(Q);
	while(Q--)
	{
		ll x;
		gi(x);
		if(st.find(x)!=st.end()) st.erase(x),sum-=x;
		else st.insert(x),sum+=x;
		ll r0=0;
		auto it1=st.begin();
		auto it2=st.rbegin();
		ll s1=0,s2=0,ans=0;
		while(it1!=st.end())
		{
			s1+=(*it1),s2+=(*it2);
			it1++,it2++;
			ans+=s2-max(s1,r0);r0=s2;
		}
		print(ans);putchar('\n');
	}
}
